package com.franklin.validation.core.config;

import com.franklin.validation.core.constants.Constants;
import com.franklin.validation.core.utils.DataCheckUtil;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

/**
 * Description :
 * Create By: Franklin
 * Date : 2020/6/4 10:24
 */
@ConfigurationProperties(prefix = "franklin.validation")
@Data
@Component
public class ValidationConfig {

    private final static String DEFAULT_CODE = HttpStatus.BAD_REQUEST.value() + "";
    private final static String DEFAULT_MESSAGE = "%s " + Constants.IS_WRONG;

    private String code;

    private String message;

    @PostConstruct
    public void init(){
        if (DataCheckUtil.isEmpty(this.code)){
            this.code = DEFAULT_CODE;
        }
        if (DataCheckUtil.isEmpty(this.message)){
            this.message = DEFAULT_MESSAGE;
        }
    }
}
